<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <link rel="stylesheet" href="css/index.css">
    <script src="js/vue.js"></script>
    <script src="js/elementui.js"></script>
    <script src="js/axios.js"></script>
    <title>注册</title>
</head>
<style>
    body {
        margin: 0px;
        background-color: #eadfdf;
    }

    #all-from {
        width: 30%;
        margin: 150px;
        background-color: #edb3f6;
        border-radius: 10px;
        box-shadow: 0 0 10px #acd8fa;
        padding: 90px;
        text-align: center;
        margin-left: 450px;
    }
</style>
<body>
    <div id="app">
        <div id="all-from">
            <h2>注册</h2>
            <el-form ref="form" :model="form" label-width="80px">
                <el-form-item label="用户名">
                    <el-input v-model="form.uname"></el-input>
                </el-form-item>
                <el-form-item label="密码">
                    <el-input type="password" v-model="form.upwd"></el-input>
                </el-form-item>
                <el-form-item>
                    <el-button type="primary" @click="onRegister">注册</el-button>
                    <el-button>取消</el-button>
                </el-form-item>
            </el-form>
        </div>
    </div>
</body>
<script>
    new Vue({
        el: '#app',
        data: {
            form: {
                uname: "",
                upwd: "",
            }
        },
        methods: {
  onRegister() {
    axios.post("http://localhost:8080/boot/userregister", this.form)
      .then((res) => {
        console.log(res);
        if (res.data.code === 200) {
          this.$message({
            message: '注册成功',
            type: 'success'
          });
          setTimeout(() => {
            window.location.href = "login.html";
          }, 1500); // 延迟1.5秒
        } else {
          this.$message({
            message: res.data.message || '注册失败',
            type: 'error'
          });
        }
      })
      .catch((error) => {
        console.error('There was an error!', error);
        this.$message({
          message: '请求失败，请稍后再试',
          type: 'error'
        });
      });
  }
}
    })
</script>
</html>